<?php
/*+--------------------------------------------------+
  |       站点用户栏目管理                           |
  +--------------------------------------------------+*/
class WebsiteColumnManageAction extends CommonAction{
    /*+--------------------------------------------+
      |        首页                                |
      +--------------------------------------------+*/
    public function index(){
           C("DB_NAME",$_SESSION[C('DATA_KEY')]);
           $col = D("website_column");
           //分页显示
           $limit = $this->pageOperate("website_column",20,"status = '1'");
           $column = $col->where("status = '1'") ->order("column_position asc,id desc") ->limit("{$limit['firstRow']},{$limit['listRows']}") ->findall();
           $this->assign("column",$column);
           $this->display();
    }

    /*+--------------------------------------------+
      |        添加栏目                            |
      +--------------------------------------------+*/
    public function addColumn(){
           //1.显示该站点下的栏目信息
                //1.1切换到该站点的数据库
           C("DB_NAME",$_SESSION[C('DATA_KEY')]);
           $col = D("website_column");
           $limit = $this->pageOperate("website_column",20);
           $column = $col->limit("{$limit['firstRow']},{$limit['listRows']}")->findall();
           $this->assign("column",$column);
           $this->display();
    }

    /*+--------------------------------------------
      |       修改栏目状态（即添加栏目）
      +--------------------------------------------*/
    public function editColumnStatus(){
        C("DB_NAME",$_SESSION[C('DATA_KEY')]);
        $col = D("website_column");
        if($_POST['add']){
            foreach($_POST['id'] as $key => $val){
                   $up += $col ->where("id = {$val}")->save(array("status"=>"1"));
            }
            if($up>0){
                $this->success("成功的添加的了：{$up} 个栏目");
            }else{
                $this->error("添加栏目失败！");
            }         
        }

        if($_GET['id']){
            $up = $col ->where("id = {$_GET['id']}")->save(array("status"=>"1"));
            if($up>0){
                $this->success("成功的添加的了：{$up} 个栏目");
            }else{
                $this->error("添加栏目失败！");
            }    
        }
    }

    /*+--------------------------------------------
      |       修改栏目状态（即删除栏目）
      +--------------------------------------------*/
    public function delColumnStatus(){
        C("DB_NAME",$_SESSION[C('DATA_KEY')]);
        $col = D("website_column");
        if($_POST['del']){
            foreach($_POST['id'] as $key => $val){
                   $up += $col ->where("id = {$val}")->save(array("status"=>"0"));
            }
            if($up>0){
                $this->success("成功的删除的了：{$up} 个栏目");
            }else{
                $this->error("删除栏目失败！");
            }         
        }

        if($_GET['id']){
            $up = $col ->where("id = {$_GET['id']}")->save(array("status"=>"0"));
            if($up>0){
                $this->success("成功的删除的了：{$up} 个栏目");
            }else{
                $this->error("删除栏目失败！");
            }    
        }

        //排序
        if($_POST['pos']){
                 //数组重组
                 $newArray = $this->arraySwitch($_POST);
                 foreach($newArray as $key => $val){
                     //逐条修改position
                     $col->save($val);
                 }
                 $this->redirect("WebsiteColumnManage/index");
        }
    }
}

?>
